package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-02-24 18:39
 **/
public class LeetCode2178 {

    public List<Long> maximumEvenSplit(long finalSum) {
        List<Long> ans = new ArrayList<>();
        if (finalSum % 2 != 0) {
            return ans;
        }

        long init = 2;
        long multi = 1;
        while (finalSum >= init * multi) {
            if (finalSum >= init * (2 * multi + 1)) {
                ans.add(init * multi);
                finalSum -= init * multi;
            } else {
                ans.add(finalSum);
                finalSum = 0;
            }
            ++multi;
        }

        return ans;
    }

}
